<% layout('/views/layouts/default.html', {title: 'Role List', libs: ['validate']}){ %>
<section class="content-header">
	<h1>Role管理</h1>
	<ol class="breadcrumb">
		<li>
			<a href="/role/listPage"><button class="btn btn-xs jfedit btn-default">刷新</button></a>&nbsp;
			<a href="/role/addPage"><button class="btn btn-xs jfedit btn-primary">新增</button></a>
		</li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	</ol>
</section>

<!-- Main content -->
<section class="content">
	<div class="row">
		<div class="col-xs-12">
			<div class="box">
				<div class="box-body">
					<table id="example" class="table table-bordered table-hover" style="width:100%">
						<thead>
							<tr>
								<th>id</th>
								<th>角色名</th>
								<th>操作</th>
							</tr>
						</thead>
						<tbody></tbody>
						<tfoot>
							<tr>
								<th>id</th>
								<th>角色名</th>
								<th>操作</th>
							</tr>
						</tfoot>
					</table>
				</div>
			</div>
		</div>
	</div>
</section>
<% } %>

<script>
$(document).ready(function() {
	$('#example').DataTable( {
		"order": [[ 0, "desc" ]],
		"ajax": "/role/list",
		"columns": [
			{ "data": "id" },
			{ "data": "roleName" },
			{ "data": "roleName" ,"width":"200px"}
		],
		"aoColumnDefs":[
		{//倒数第一列
			"targets":-1,
			"bSortable": false,
			render: function(data, type, row) {
				var html ='<a href="/role/editMenuRolePage?id='+row.id+'"><button class="btn btn-xs jfedit btn-info" value="'+row.id+'">权限</button></a>&nbsp;&nbsp;&nbsp;&nbsp;'
				+'<a href="/role/editPage?id='+row.id+'"><button class="btn btn-xs jfedit btn-info" value="'+row.id+'">编辑</button></a>&nbsp;&nbsp;&nbsp;&nbsp;'
				+'<button onclick="delFun('+row.id+')" id="delButton" class="btn btn-xs btn-danger jfdelete">删除</button>';
				return html;
			}
		}]
	});
});

function delFun(id){
	if(confirm("确定删除嘛？")){
		$.ajax({
			url:"/role/delete?id=" + id,
			success:function(data){
				alert(data.resMsg);
				window.location.href="/role/listPage";
			}
		});
	};
}
</script>
